package com.huawei.classroom.student.h15;

import java.util.ArrayList;
import java.util.List;

public class NewThread extends Thread{
	private List<Long> list = new ArrayList<>();//每个线程一个装质数的List
	private long start;
	private long end;
	public NewThread(long start, long end) {
		this.start = start;
		this.end = end;
	}
	public List<Long> getlist() {
		return list;//这个太重要了
	}
	@Override
	public void run() {
		for(long i=this.start; i<end; i++) {
			if(judge(i) == true) {
				list.add(i);
			}
		}
	}
	
	public boolean judge(long i) {//判断质数
		if(i == 2) return true;
		for(long j=2; j<Math.sqrt(i)+1; j++) {//只到Math.sqrt(i)就行了，数学思想
			if(i % j == 0) {
				return false;
			}
		}
		return true;
	}
	
}
